//
//  YDUserViewModel.swift
//  weibo
//
//  Created by 孙亚东 on 16/6/27.
//  Copyright © 2016年 Sunyadong. All rights reserved.
//

import UIKit

class YDUserViewModel: NSObject {


    var model: YDStatusModel?
    
    
     init (model: YDStatusModel ) {
        
        self.model = model
        
        super.init()
        
    }

    
    var photoUrl: NSURL? {
        
        if let urlStrig = model?.user?.profile_image_url{
            // 赋值
            return NSURL(string: urlStrig)
            
        }
        return NSURL()
    }
    
    ///   昵称
    var name: String? {
        return model?.user?.screen_name
    }
    ///  内容
    var content: String?{
        return model?.text
    }
    ///等级图片
    var levelImage: UIImage? {
        
        if let level = model?.user?.mbrank {
            
            return UIImage(named: "common_icon_membership_level\(level)")
            
        }
        
        return UIImage()
    }
    /// 认证图片
    var verifyImage: UIImage? {
        
        if let type = model?.user?.verified_type {
            
            switch type {
                
            case -1: return UIImage()
            case 0: return UIImage(named: "avatar_grassroot")
            case 2,3,5: return UIImage(named: "avatar_enterprise_vip")
            case 220: return UIImage(named: "avatar_vip")
                
            default : return UIImage()
                
            }
            
        }
        
        return UIImage()
        
    }
    //转发按钮的标题
    var retweetString: String? {
        
        if model?.reposts_count == 0 {
            return "转发"
        } else {
            return "\(model?.reposts_count ?? 0)"
        }
        
    }
    
    ///  评论按钮标题
    var commentString: String? {
        if model?.comments_count == 0 {
            return "评论"
        } else {
            return "\(model?.comments_count ?? 0)"
        }
    }
    ///  点赞按钮的标题
    var goodString: String? {
        
        if model?.attitudes_count == 0 {
            
            return "赞"
        } else {
            
            return  "\(model?.attitudes_count ?? 0)"
        }
        
    }
    
    // 获取转发的内容
    
    var reweetString: String? {
    
        
        if let reweetString = model?.retweeted_status?.text {
        
        
            return reweetString
        
        
        }else {
        
        
            return nil
        
        
        }
 
    
    }
 
}
